//
//  AppDelegate.swift
//  SwiftDemoWithSina
//
//  Created by qu on 2017/1/16.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        //创建window
        self.window = UIWindow(frame: UIScreen.main.bounds)
        //设置背景颜色
        self.window?.backgroundColor = UIColor.white
        //设置根视图控制器
        self.window?.rootViewController = setupRootViewController()
        //设置主窗口并显示可见
        self.window?.makeKeyAndVisible()
        
        //注册通知
        NotificationCenter.default.addObserver(self, selector: #selector(switchRootViewContoller), name: NSNotification.Name(rawValue: SWITCHROOTVIEWCONTROLLERNOTI), object: nil)
        
        
        return true
    }
    @objc private func switchRootViewContoller(noti: Notification){
        
        window?.rootViewController = noti.object == nil ? QCWelcomeViewController() :QCMainViewController()
    }

    private func setupRootViewController() ->UIViewController{
        
        return !QCOAuthViewModel.shared.isLogin == true ? QCMainViewController():QCWelcomeViewController()
     }
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
}

